package com.liqi.display.api;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import com.liqi.display.entity.returnType.WaitAndGetTimeForArea;
import com.liqi.display.entity.returnType.WaitAndGetTotal;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.liqi.display.common.Constants;
import com.liqi.display.common.Results;
import com.liqi.display.common.SystemCode;
import com.liqi.display.entity.returnType.TopEightTask;
import com.liqi.display.utils.DateUtil;
import com.liqi.display.utils.HttpUtils;
import com.liqi.display.utils.RedisUtil;

/**
 * 获取大屏数据API
 * @author liqi
 * @since 2021-04-13
 */
@RestController
@RequestMapping("/display/api")
public class DisplayWebApi {

    private static final Logger logger = LoggerFactory.getLogger(DisplayWebApi.class);

    @Autowired
    RedisUtil redisUtil;

    /**
     * 0.当天业务量统计分析
     * @return
     */
    @GetMapping("/getDayTotalData")
    public Results getDayTotalData(){
        Results results = new Results();
        Map<String,Object> maps = new ConcurrentHashMap<String,Object>();
        try {
            //获取当天的取号总数
            int numDayTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(), Constants.DAY), Constants.NUM_DAY_TATAL);
            //获取当天预约总数
            int orderDayTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(), Constants.DAY), Constants.ORDER_DAY_TATAL);
            //获取当天现场取号数
            int xcNumDayTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.DAY),Constants.NUM_XC_DAY_TATAL);
            //获取当天预约取号数
            int yyNumDayTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.DAY),Constants.NUM_YY_DAY_TATAL);
            //当前发证件总数
            int sendNum = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.DAY),Constants.NUM_SEND_DAY_TATAL);
            //当前收件总数
            int receiveNum = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.DAY),Constants.NUM_RECEIVE_DAY_TATAL);
            //微信取号数
            int wxTakeNumNum = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.DAY),Constants.NUM_WX_DAY_TATAL);

            maps.put(Constants.NUM_DAY_TATAL,numDayTotal);//获取当天的取号总数
            maps.put(Constants.ORDER_DAY_TATAL,orderDayTotal);//获取当天预约总数
            maps.put(Constants.NUM_XC_DAY_TATAL,xcNumDayTotal); //获取当天现场取号数
            maps.put(Constants.NUM_YY_DAY_TATAL,yyNumDayTotal);//获取当天预约取号数
            maps.put(Constants.NUM_SEND_DAY_TATAL,sendNum);//当前发证件总数
            maps.put(Constants.NUM_RECEIVE_DAY_TATAL,receiveNum);//当前收件总数
            maps.put(Constants.NUM_WX_DAY_TATAL,wxTakeNumNum);//微信取号数
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取日统计数!");
            results.setData(maps);
            return results;
        }catch (Exception e) {
            logger.error("getDayTotalDatay异常信息:{}",e.getStackTrace());
            maps.put(Constants.NUM_DAY_TATAL,121);
            maps.put(Constants.ORDER_DAY_TATAL,132);
            maps.put(Constants.NUM_XC_DAY_TATAL,28);
            maps.put(Constants.NUM_YY_DAY_TATAL,83);
            maps.put(Constants.NUM_SEND_DAY_TATAL,21);
            maps.put(Constants.NUM_RECEIVE_DAY_TATAL,121);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取日统计数!");
            results.setData(maps);
            return results;
        }
    }

    /**
     * 1.获取当前业务量统计
     * @return
     */
    @GetMapping("/getDayBusinessTotalData")
    public Results getDayBusinessTotalData(){
        Results results = new Results();
        Map<String,Object> maps = new ConcurrentHashMap<String,Object>();
        try {
            //获取当天预约总数
            int numDayTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(), Constants.DAY), Constants.NUM_DAY_TATAL);
            int totalComplete = (int)redisUtil.hashGet(DateUtil.format(new Date(), Constants.DAY), Constants.TOTAL_COMPLETE);
            int totalDoing = (int)redisUtil.hashGet(DateUtil.format(new Date(), Constants.DAY), Constants.TOTAL_DOING);
            int totalWaiting = (int)redisUtil.hashGet(DateUtil.format(new Date(), Constants.DAY), Constants.TOTAL_WAITING);
            maps.put(Constants.NUM_DAY_TATAL,numDayTotal);//获取当天预约总数
            maps.put(Constants.TOTAL_COMPLETE,totalComplete);//已经办结
            maps.put(Constants.TOTAL_DOING,totalDoing);//正在办理
            maps.put(Constants.TOTAL_WAITING,totalWaiting);//当前等待
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取当前业务量统计");
            results.setData(maps);
            return results;
        }catch (Exception e) {
            logger.error("getDayBusinessTotalData 异常信息:{}",e.getStackTrace());
            maps.put(Constants.NUM_DAY_TATAL,132);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取当前业务量统计");
            results.setData(maps);
            return results;
        }
    }

    /**
     * 2.当天平均等待受理时间
     * @return
     */
    @GetMapping("getAverageNum")
    public Results getAverageNum(){
        Results results=new Results();
        Map<String,Object> map = new ConcurrentHashMap<>();
        try {
            //获取月份数字
            int monthNum = DateUtil.getMonthNum();
            //统计每个月的平均等待时长
            Object waitNum = redisUtil.hashGet(Constants.MONTH_AVERAGE_WAIT_NUM, monthNum + "");
            //统计每个月的平均受理时长
            Object acceptNum = redisUtil.hashGet(Constants.MONTH_AVERAGE_ACCEPT_NUM,monthNum+"");
            //月好评数
            Object evaluateNum = redisUtil.hashGet(Constants.MONTH_GOOD_EVALUATE_NUM,monthNum+"");
            //月好评数
            Object yesterdayWaitNum = redisUtil.hashGet(Constants.YESTERDAY_AVERAGE_WAIT_NUM,monthNum+"");
            //月好评数
            Object yesterDayEvaluateNum = redisUtil.hashGet(Constants.YESTERDAY_AVERAGE_ACCEPT_NUM,monthNum+"");
            map.put(Constants.WAIT_NUM,waitNum);
            map.put(Constants.ACCEPT_NUM,acceptNum);
            map.put(Constants.EVALUATE_NUM,evaluateNum);
            map.put(Constants.YESTERDAY_WAIT_NUM,yesterdayWaitNum);
            map.put(Constants.YESTERDAY_ACCEPT_NUM,yesterDayEvaluateNum);
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取每个月平均等待、平均受理时长、好评数");
            return results;
        }catch (Exception e){
            logger.error("getAverageNum异常信息:{}"+e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setData(map);
            return results;
        }
    }

    /**
     * 3.当天的各时段取号量
     * @return
     */
    @GetMapping("/getDayAcceptNumInit")
    public Results getDayAcceptNumInit(){
        Results results=new Results();
        Map<String,Map<String,Object>> map = new ConcurrentHashMap<>();
        try {
            map.put(Constants.TODAYKEY_PERSON_NUM,(Map)redisUtil.hashGet(Constants.TODAY_PERSON_NUM, Constants.TODAYKEY_PERSON_NUM));
            map.put(Constants.LASTWEEK_TODAYKEY_PERSON_NUM,(Map)redisUtil.hashGet(Constants.LASTWEEK_TODAY_PERSON_NUM, Constants.LASTWEEK_TODAYKEY_PERSON_NUM));
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取当天的各时段取号量的人流对比");
            return results;
        }catch (Exception e){
            logger.error("getDayAcceptNumInit 异常信息:{}"+e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setData(map);
            return results;
        }
    }

    /**
     * 4.当天各业务区等待量/取号量TOP10
     * @return
     */
    @GetMapping("/getTotalWaitingAndGetting")
    public Results getTotalWaitingAndGetting(){
        Results results=new Results();
        Map<String,Object>map=new ConcurrentHashMap<>();
        try {
            List<WaitAndGetTotal> waitAndGetTotalList  = (List)redisUtil.hashGet(Constants.WAITING_GETTING_RATE, Constants.WAITING_GETTING_COUNT);
            map.put(Constants.WAITING_GETTING_COUNT,waitAndGetTotalList);
            results.setData(map);
            results.setMessage("各业务区排队量、取号量");
            results.setCode(SystemCode.SYS_OK.getKey());
            return results;
        }catch (Exception e){
            logger.error("getTotalWaitingAndGetting 异常信息:{}"+e.getMessage());
            List<WaitAndGetTotal> waitAndGetTotalList =new ArrayList<>();
            map.put(Constants.WAITING_GETTING_COUNT,waitAndGetTotalList);
            results.setData(map);
            results.setMessage("各业务区排队量、取号量");
            results.setCode(SystemCode.SYS_OK.getKey());
            return results;
        }
    }

    /**
     * 5.近七天各渠道数据
     * @return
     */
    @GetMapping("/sevenDayChannelDataTotal")
    public Results sevenDayChannelDataTotal(){
        Results results=new Results();
        Map<String,Map<String,Object>> map = new ConcurrentHashMap<>();
        try {
            map.put(Constants.GET_TICK_CHANNEL_COUNT_KEY,(Map)redisUtil.hashGet(Constants.GET_TICK_CHANNEL_COUNT, Constants.GET_TICK_CHANNEL_COUNT_KEY));
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取近七天各渠道取号量的人流对比");
            return results;
        }catch (Exception e){
            logger.error("sevenDayChannelDataTotal 异常信息:{}"+e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setData(map);
            return results;
        }
    }

    /**
     * 6.近七天各渠道申办量
     * @return
     */
    @RequestMapping("getAcceptWeekNum")
    public Results getAcceptWeekNum(){
        Results r = new Results();
        try {
            Map<String, Integer> map = ( Map<String, Integer>)redisUtil.hashGet(Constants.PACCEPT_WEEK_NUM,Constants.CACCEPT_WEEK_NUM);
            r.setData(map);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取办理方式数");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 7.近七天文件柜存取件数量对比
     * @return
     */
    @RequestMapping("getDocLate10Num")
    public Results getDocLate10Num(){
        Results r = new Results();
        try {
            Map<String,String> lateTenNumMap = (Map<String,String>)redisUtil.hashGet(Constants.PRECEIVE_TYPE_LATE_TEN,Constants.CRECEIVE_TYPE_LATE_TEN);
            r.setData(lateTenNumMap);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取文件柜最近10天放件人类型对比");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 8.近七天取票方式趋势图
     *      预约取号、现场取号
     * @return
     */
    @GetMapping("getTakeNumTypeNum")
    public Results getTakeNumTypeNum(){
        Results results=new Results();
        Map<String,Object> map = new ConcurrentHashMap<>();
        try {
            Map<String, Integer> orderNumMap =(Map<String, Integer>)redisUtil.hashGet(Constants.PTAKE_NUM_TYPE,Constants.ORDER_NUM_TYPE);
            Map<String, Integer> currNumMap =(Map<String, Integer>)redisUtil.hashGet(Constants.PTAKE_NUM_TYPE,Constants.CURR_NUM_TYPE);
            //Map<String, Integer> weixinNumMap =(Map<String, Integer>)redisUtil.hashGet(Constants.PTAKE_NUM_TYPE,Constants.WEIXIN_NUM_TYPE);
            map.put(Constants.ORDER_NUM_TYPE,orderNumMap);
            map.put(Constants.CURR_NUM_TYPE,currNumMap);
            //map.put(Constants.WEIXIN_NUM_TYPE,weixinNumMap);
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("最近七天取票方式趋势图，包含现场取号、预约取号");
            return results;
        }catch (Exception e){
            logger.error("获取取票方式对比，现场取号、预约取号异常信息:{}"+e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setData(map);
            return results;
        }
    }

    //9.每月各渠道业务受理量
    @RequestMapping("getAcceptMethodNum")
    public Results getAcceptMethodNum(){
        Results r = new Results();
        try {
            Map<String, Map<String, String>> map = (Map<String, Map<String, String>>) redisUtil.hashGet(Constants.PACCEPT_METHOD_NUM,Constants.CACCEPT_METHOD_NUM);
            r.setData(map);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取办理方式数");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 10.近30天按时办结统计
     * @return
     */
    @RequestMapping("getFinishRate")
    public Results getFinishRate(){
        Results r = new Results();
        try {
            Map<String,String> finishRateMap = (Map<String,String>)redisUtil.hashGet(Constants.FINISH_RATE,Constants.FINISH_COUNT);
            r.setData(finishRateMap);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取近30天办结率");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 11.近30天各业务区域申办量统计
     * @return
     */
    @RequestMapping("getZoneAcceptNum")
    public Results getZoneAcceptNum(){
        Results r = new Results();
        try {
            Map<String, Integer> map = ( Map<String, Integer>)redisUtil.hashGet(Constants.PZONE_ACCEPT_NUM,Constants.CZONE_ACCEPT_NUM);
            r.setData(map);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取专窗受理量");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage("获取专窗受理量");
            return r;
        }
    }

    /**
     * 12.近30天好差评率统计
     * @return
     */
    @RequestMapping("getLately7SatisficationNum")
    public Results getLately7SatisficationNum(){
        Results r = new Results();
        try {
            Map<String,String> map = (Map<String,String>)redisUtil.hashGet(Constants.PZONE_GOODS_BAD_SATISFICATION_NUM,Constants.CZONE_GOODS_BAD_SATISFICATION_NUM);
            r.setData(map);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取最近天好评差评数");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 13.近30天各业务区域好差评得分排名（满分5分）
     * @return
     */
    @RequestMapping("getZoneSatisficationNum")
    public Results getZoneSatisficationNum(){
        Results r = new Results();
        try {
            Map<String,String> persentageMap = (Map<String,String>)redisUtil.hashGet(Constants.PZONE_SATISFICATION_NUM,Constants.CZONE_SATISFICATION_NUM);
            //persentageMap.remove(Constants.QZH_ZONE);
            //persentageMap.remove(Constants.SZH_ZONE);
            r.setData(persentageMap);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取专窗满意度");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 14.各业务区等待与受理时间
     * @return
     */
    @GetMapping("/getTotalWaitingAndGettingTimeForArea")
    public Results getTotalWaitingAndGettingTimeForArea(){
        Results results=new Results();
        Map<String,Object>map=new ConcurrentHashMap<>();
        try {
            List<WaitAndGetTimeForArea> waitTimeForArea  = (List)redisUtil.hashGet(Constants.WAITING_GETTING_TIME, Constants.WAITING_GETTING_TIME_COUNT);
            map.put(Constants.WAITING_GETTING_TIME_COUNT,waitTimeForArea);
            results.setData(map);
            results.setMessage("各业务区等待与受理时间");
            results.setCode(SystemCode.SYS_OK.getKey());
            return results;
        }catch (Exception e){
            logger.error("getTotalWaitingAndGettingTimeForArea 异常信息:{}"+e);
            List<WaitAndGetTimeForArea> waitTimeForArea =new ArrayList<>();
            map.put(Constants.WAITING_GETTING_TIME_COUNT,waitTimeForArea);
            results.setData(map);
            results.setMessage("各业务区等待与受理时间");
            results.setCode(SystemCode.SYS_OK.getKey());
            return results;
        }
    }

    //15.近30天业务申办量Top8
    /**
     * 获取近30天事项申办量top8(近30天热门事项前八)
     * @return
     */
    @GetMapping("/getMonthTopEightItem")
    public Results getMonthTopEightItem(){
        Results results=new Results();
        Map<String,Object>map=new ConcurrentHashMap<>();
        try {
            List<TopEightTask> topEightTasks = (List)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH), Constants.TOP_EIGHT_ITEM_MONTH);
            map.put(Constants.TOP_EIGHT_ITEM_MONTH,topEightTasks);
            results.setData(map);
            results.setMessage("获取当月热门事项前八");
            results.setCode(SystemCode.SYS_OK.getKey());
            return results;
        }catch (Exception e){
            logger.error("getTopEightMonth异常信息:{}"+e.getMessage());
            List<TopEightTask> topEightTasks=new ArrayList<>();
            topEightTasks.add(new TopEightTask("公积金查询",500,4));
            topEightTasks.add(new TopEightTask("公章刻制",460,4));
            topEightTasks.add(new TopEightTask("医师执业注册",430,4));
            topEightTasks.add(new TopEightTask("不动产登记",400,4));
            topEightTasks.add(new TopEightTask("医保办理登记",380,4));
            topEightTasks.add(new TopEightTask("身份证挂失补办",350,4));
            topEightTasks.add(new TopEightTask("社保查询",280,4));
            topEightTasks.add(new TopEightTask("失业登记",200,4));
            map.put(Constants.TOP_EIGHT_ITEM_MONTH,topEightTasks);
            results.setData(map);
            results.setMessage("获取当月热门事项前八");
            results.setCode(SystemCode.SYS_OK.getKey());
            return results;
        }
    }

    /**
     * 16.近30天业务量统计
     * @return
     */
    @GetMapping("/getMonthTotalData")
    public Results getMonthTotalData(){
        Results results = new Results();
        Map<String,Object> maps = new ConcurrentHashMap<String,Object>();
        try {
            //本月取号总数
            int numMonthTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.NUM_MONTH_TATAL);
            //本月满预约数
            int orderMonthTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.ORDER_MONTH_TATAL);
            //本月现场取号数
            int xcMonthTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.NUM_XC_MONTH_TATAL);
            //本月预约取号数
            int yyMonthTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.NUM_YY_MONTH_TATAL);
            //本月发证件总数
            int sendMonthTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.NUM_SEND_MONTH_TATAL);
            //本月取收件数
            int receiveMonthTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.NUM_RECEIVE_MONTH_TATAL);
            //微信取号数
            int wxTakeNumTotal = (int)redisUtil.hashGet(DateUtil.format(new Date(),Constants.MONTH),Constants.NUM_WX_MONTH_TATAL);
            maps.put(Constants.NUM_MONTH_TATAL,numMonthTotal);//本月取号总数
            maps.put(Constants.ORDER_MONTH_TATAL,orderMonthTotal);//本月满预约数
            maps.put(Constants.NUM_XC_MONTH_TATAL,xcMonthTotal);//本月现场取号数
            maps.put(Constants.NUM_YY_MONTH_TATAL,yyMonthTotal);//本月预约取号数
            maps.put(Constants.NUM_SEND_MONTH_TATAL,sendMonthTotal); //本月发证件总数
            maps.put(Constants.NUM_RECEIVE_MONTH_TATAL,receiveMonthTotal);//本月取收件数
            maps.put(Constants.NUM_WX_MONTH_TATAL,wxTakeNumTotal);//微信取号数
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取月统计数集!");
            results.setData(maps);
            return results;
        }catch (Exception e) {
            maps.put(Constants.NUM_MONTH_TATAL,528);//本月取号总数
            maps.put(Constants.ORDER_MONTH_TATAL,333);//本月满预约数
            maps.put(Constants.NUM_XC_MONTH_TATAL,208);//本月现场取号数
            maps.put(Constants.NUM_YY_MONTH_TATAL,320);//本月预约取号数
            maps.put(Constants.NUM_SEND_MONTH_TATAL,198);//本月发证件总数
            maps.put(Constants.NUM_RECEIVE_MONTH_TATAL,528);//本月取收件数
            maps.put(Constants.NUM_WX_MONTH_TATAL,123);//微信取号数
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取月统计数集!");
            logger.error("getMonthTotalData异常信息:{}",e.getMessage());
            results.setData(maps);
            return results;
        }
    }

    /**
     * 16.1 近30天业务量统计
     * 获取最近30天 每天的 收件量 发证量
     * @return
     */
    @GetMapping("getLate30SRNum")
    public Results getLate30SRNum(){
        Results results=new Results();
        Map<String,Object> map = new ConcurrentHashMap<>();
        try {
            Map<String, Integer> lateReceiveNumMap =(Map<String, Integer>)redisUtil.hashGet(Constants.LATELY_30, Constants.LATELY30_RECEIVE_NUM);
            Map<String, Integer> lateSenNumMap =(Map<String, Integer>)redisUtil.hashGet(Constants.LATELY_30,Constants.LATELY30_SEND_NUM);
            map.put(Constants.LATELY30_RECEIVE_NUM,lateReceiveNumMap);
            map.put(Constants.LATELY30_SEND_NUM,lateSenNumMap);
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("最近30天收发证量");
            return results;
        }catch (Exception e){
            logger.error("获取最近30天收发证量异常信息:{}"+e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setData(map);
            return results;
        }
    }

    /**
     * 获取最近7天30天的人流对比
     * @return
     */
    @GetMapping("getLatePersonNum")
    public Results getLatePersonNum(){
        Results results=new Results();
        Map<String,Map<String,Object>> map = new ConcurrentHashMap<>();
        try {
            map.put(Constants.LATELY7_PERSON_NUM,(Map)redisUtil.hashGet(Constants.LATELY_PERSON_NUM, Constants.LATELY7_PERSON_NUM));
            map.put(Constants.LATELY30_PERSON_NUM,(Map)redisUtil.hashGet(Constants.LATELY_PERSON_NUM, Constants.LATELY30_PERSON_NUM));
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage("获取最近7天30天的人流对比");
            return results;
        }catch (Exception e){
            logger.error("getLateDateNum异常信息:{}"+e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setData(map);
            return results;
        }
    }

    /**
     * 事项同源统计，是否本地化事项
     * @return
     */
    @RequestMapping("getLocalRate")
    public Results getLocalRate(){
        Results r = new Results();
        try {
            Map<String,String> localRateMap = (Map<String,String>)redisUtil.hashGet(Constants.LOCAL_RATE,Constants.LOCAL_COUNT);
            r.setData(localRateMap);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取本地化事项比例");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 近30天退件率
     * @return
     */
    @RequestMapping("getSendBackRate")
    public Results getSendBackRate(){
        Results r = new Results();
        try {
            Map<String,String> sendBackRateMap = (Map<String,String>)redisUtil.hashGet(Constants.SENDBACK_RATE,Constants.SENDBACK_COUNT);
            r.setData(sendBackRateMap);
            r.setCode(SystemCode.SYS_OK.getKey());
            r.setMessage("获取近30天退件率");
            return r;
        }catch (Exception e){
            r.setCode(SystemCode.SYS_FAIL.getKey());
            r.setMessage(SystemCode.SYS_FAIL.getValue());
            return r;
        }
    }

    /**
     * 获取天气信息
     * @return
     */
    @RequestMapping("getWeather")
    public Results getWeather(){
        Results results =new Results();
        try {
            Map<String, Object> map = new ConcurrentHashMap<>();
            String url = "http://api.map.baidu.com/weather/v1/";
            String params = "district_id=360727&data_type=all&ak="+Constants.BAIDU_AK;
            String sendGetStr = HttpUtils.sendGet(url, params);
            if(!StringUtils.isEmpty(sendGetStr)) {
                results.setCode(SystemCode.SYS_OK.getKey());
                results.setMessage(SystemCode.SYS_OK.getValue());
                JSONObject datas = JSON.parseObject(sendGetStr);
                JSONObject result = datas.getJSONObject("result");
                JSONArray forecasts = result.getJSONArray("forecasts");
                forecasts.remove(4);
                results.setData(datas);
            }else {
                results.setCode(SystemCode.SYS_OK.getKey());
                results.setMessage(SystemCode.SYS_OK.getValue());
                results.setData(null);
            }
            return results;
        }catch (Exception e){
            logger.info("异常信息",e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }
    
}
